]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Complex Components/MapRender/MapRenderView.swift
Add search
[rbdr/map] / Map / Presentation / Complex Components / MapRender / MapRenderView.swift
1 /*
2 Copyright (C) 2024 Rubén Beltrán del Río
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see https://map.tranquil.systems.
16 */
17 import Combine
18 import CoreData
19 import CoreGraphics
20 import SwiftUI
21
22 struct MapRenderView: View {
23
24 @Binding var document: MapDocument
25 @Binding var evolution: StageType
26
27 var stage: Stage {
28 Stage.stages(evolution)
29 }
30
31 var parsedMap: ParsedMap {
32 MapParser.parse(content: document.text)
33 }
34
35 let mapSize = Dimensions.mapSize
36 let padding = Dimensions.mapPadding
37
38 let lineWidth = CGFloat(0.5)
39 let vertexSize = CGSize(width: 25.0, height: 25.0)
40
41 var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in }
42
43 var body: some View {
44 ZStack(alignment: .topLeading) {
45
46 Path { path in
47 path.addRect(
48 CGRect(
49 x: -padding, y: -padding, width: mapSize.width + padding * 2,
50 height: mapSize.height + padding * 4))
51 }.fill(.white)
52
53 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
54 MapAxes(
55 mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
56 MapEdges(
57 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
58 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
59 MapVertices(
60 mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
61 onDragVertex: onDragVertex)
62 MapOpportunities(
63 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
64 opportunities: parsedMap.opportunities)
65 MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
66 opaque: true
67 ).opacity(0.1)
68 MapNotes(
69 mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
70 }.offset(x: padding, y: padding).frame(
71 width: mapSize.width + 2 * padding,
72 height: mapSize.height + 2 * padding, alignment: .topLeading
73 )
74 }
75 }
76
77 #Preview {
78 MapRenderView(
79 document: Binding.constant(MapDocument(text: "")),
80 evolution: Binding.constant(StageType.general)
81 )
82 }